home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 February / macformat-047.iso / Demos / Simpsons Cartoon Studio™ Demo / Simpdata / simpmain / 00010_fileManager parent.ls < prev    next >
Encoding:
Text File  |  1996-09-06  |  23.6 KB  |  831 lines

  1. property nextAction, currentCartoonName, currentCartoonCredits, toonDataFileName, toonDataFileNameToDelete, unsortedFileList, sortedFileList
  2. global fileDataList, scoreData, bgdData, bgdFXData, fgdFXData, soundFXData, soundLoopData, dispatchTable, toonDataFileList, dirtyFlag, breakChar, saveDialogBox, openDialogBox, exportDialogBox, dlogdataPath, toondataPath, exportPath, playBackMode, indexOfFileToExport, PCflag, runningOffCDflag, MSfileObj, contentList, savedToonDataIndex, fileObj
  3.  
  4. on birth me
  5.   set contentList to [EMPTY, []]
  6.   set currentCartoonName to "Untitled"
  7.   set currentCartoonCredits to EMPTY
  8.   set fileDataList to [currentCartoonName, currentCartoonCredits, 0, contentList]
  9.   set nextAction to EMPTY
  10.   set newFlag to 0
  11.   set toonDataFileList to []
  12.   set toonDataFileName to EMPTY
  13.   set breakChar to numToChar(165)
  14.   return me
  15. end
  16.  
  17. on exportCartoon me
  18.   set theMessage to the text of field "Demo Message"
  19.   set theAlertBoxType to #OK
  20.   showTheAlertBox(theMessage, theAlertBoxType, "nothing", "nothing", "nothing")
  21. end
  22.  
  23. on doExportDialogBox me
  24.   cursor(4)
  25.   buildToonDataFileList(me)
  26.   if toonDataFileList <> EMPTY then
  27.     openExportDialogBox(me)
  28.   else
  29.     set theMessage to "Sorry, there are no cartoons to export."
  30.     set theAlertBoxType to #OK
  31.     showTheAlertBox(theMessage, theAlertBoxType, "nothing", "nothing", "nothing")
  32.   end if
  33.   cursor(-1)
  34. end
  35.  
  36. on openExportDialogBox me
  37.   if objectp(exportDialogBox) then
  38.     forget(exportDialogBox)
  39.   end if
  40.   set exportDialogBox to window "exportDialogBox"
  41.   set h to the stageLeft + 140
  42.   set v to the stageTop + 70
  43.   set the rect of exportDialogBox to rect(h, v, h + 336, v + 294)
  44.   set the fileName of exportDialogBox to dlogdataPath & "export"
  45.   set the windowType of exportDialogBox to 2
  46.   open(exportDialogBox)
  47. end
  48.  
  49. on openCartoon me
  50.   if dirtyFlag then
  51.     set theMessage to "Do you want to save your changes before opening a new cartoon?"
  52.     set theAlertBoxType to #dontsave_cancel_save
  53.     showTheAlertBox(theMessage, theAlertBoxType, "doOpenDialogBox(fileMgr)", "nothing", "doSaveThenNextAction(fileMgr, #open)")
  54.   else
  55.     doOpenDialogBox(me)
  56.   end if
  57. end
  58.  
  59. on doOpenDialogBox me
  60.   cursor(4)
  61.   buildToonDataFileList(me)
  62.   if toonDataFileList <> EMPTY then
  63.     openOpenDialogBox(me)
  64.   else
  65.     set theMessage to "Sorry, there are no cartoons to open."
  66.     set theAlertBoxType to #OK
  67.     showTheAlertBox(theMessage, theAlertBoxType, "nothing", "nothing", "nothing")
  68.   end if
  69.   cursor(-1)
  70. end
  71.  
  72. on openOpenDialogBox me
  73.   if objectp(openDialogBox) then
  74.     forget(openDialogBox)
  75.   end if
  76.   set openDialogBox to window "openDialogBox"
  77.   set h to the stageLeft + 140
  78.   set v to the stageTop + 70
  79.   set the rect of openDialogBox to rect(h, v, h + 336, v + 294)
  80.   set the fileName of openDialogBox to dlogdataPath & "open"
  81.   set the windowType of openDialogBox to 2
  82.   open(openDialogBox)
  83. end
  84.  
  85. on doSaveThenNextAction me, whatNext
  86.   set nextAction to whatNext
  87.   saveCartoon(me)
  88. end
  89.  
  90. on saveCartoon me
  91.   exportCartoon(me)
  92. end
  93.  
  94. on copyCartoon me
  95.   exportCartoon(me)
  96. end
  97.  
  98. on generateCopyCartoonName me
  99.   set numberOfWords to the number of words in currentCartoonName
  100.   set numberOfChars to the number of chars in currentCartoonName
  101.   if numberOfChars <= 12 then
  102.     if word numberOfWords of currentCartoonName = "copy" then
  103.       if numberOfChars <= 9 then
  104.         return currentCartoonName && "2"
  105.       end if
  106.     else
  107.       if numberOfWords > 1 then
  108.         if integerp(integer(word numberOfWords of currentCartoonName)) and (word numberOfWords - 1 of currentCartoonName = "copy") then
  109.           set tempName to currentCartoonName
  110.           set count to integer(word numberOfWords of tempName + 1)
  111.           if count > 9 then
  112.             set count to 1
  113.           end if
  114.           put count into word numberOfWords of tempName
  115.           return tempName
  116.         else
  117.           if numberOfChars <= 5 then
  118.             return currentCartoonName && "copy"
  119.           end if
  120.         end if
  121.       else
  122.         if numberOfChars <= 5 then
  123.           return currentCartoonName && "copy"
  124.         end if
  125.       end if
  126.     end if
  127.   end if
  128.   return currentCartoonName
  129. end
  130.  
  131. on openSaveDialogBox me
  132.   if objectp(saveDialogBox) then
  133.     forget(saveDialogBox)
  134.   end if
  135.   set saveDialogBox to window "saveDialogBox"
  136.   set h to the stageLeft + 140
  137.   set v to the stageTop + 70
  138.   set the rect of saveDialogBox to rect(h, v, h + 336, v + 264)
  139.   set the fileName of saveDialogBox to dlogdataPath & "save"
  140.   set the windowType of saveDialogBox to 2
  141.   open(saveDialogBox)
  142. end
  143.  
  144. on writetoonData me, cartoonName, cartoonCredits
  145.   set the visible of saveDialogBox to 0
  146.   updateStage()
  147.   cursor(4)
  148.   showStatusBar("Saving Cartoon...")
  149.   updateStatusBar(1)
  150.   setCurrentCartoonName(me, cartoonName)
  151.   updateStatusBar(1)
  152.   setCurrentCartoonCredits(me, cartoonCredits)
  153.   updateStatusBar(1)
  154.   set toonDataFileName to getNewFileName(me)
  155.   updateStatusBar(1)
  156.   set fileDataList to []
  157.   updateStatusBar(1)
  158.   append(fileDataList, cartoonName)
  159.   updateStatusBar(1)
  160.   append(fileDataList, flattenCredits(me, cartoonCredits))
  161.   updateStatusBar(1)
  162.   append(fileDataList, estimateCastSize(listMgr) / 1024)
  163.   updateStatusBar(1)
  164.   append(fileDataList, contentList)
  165.   updateStatusBar(1)
  166.   writeFILEIO(me)
  167.   updateStatusBar(100)
  168.   set dirtyFlag to 0
  169.   cursor(-1)
  170.   if nextAction = #open then
  171.     set nextAction to EMPTY
  172.     doOpenDialogBox(me)
  173.   else
  174.     if nextAction = #new then
  175.       set nextAction to EMPTY
  176.       reset(appMgr)
  177.     else
  178.       if nextAction = #EXPORT then
  179.         set nextAction to EMPTY
  180.         doExportDialogBox(me)
  181.       else
  182.         if nextAction = #quit then
  183.           set nextAction to EMPTY
  184.           justQUit(appMgr)
  185.         else
  186.           updateFileNameField(appMgr)
  187.         end if
  188.       end if
  189.     end if
  190.   end if
  191. end
  192.  
  193. on writeChangesToToonData me
  194.   cursor(4)
  195.   showStatusBar("Saving Cartoon...")
  196.   updateStatusBar(1)
  197.   setAt(fileDataList, 2, flattenCredits(me, getAt(fileDataList, 2)))
  198.   updateStatusBar(1)
  199.   setAt(fileDataList, 3, estimateCastSize(listMgr) / 1024)
  200.   updateStatusBar(1)
  201.   updateContentList(me)
  202.   updateStatusBar(1)
  203.   setAt(fileDataList, 4, contentList)
  204.   updateStatusBar(1)
  205.   writeFILEIO(me)
  206.   updateStatusBar(100)
  207.   set dirtyFlag to 0
  208.   cursor(-1)
  209.   if nextAction = #open then
  210.     set nextAction to EMPTY
  211.     doOpenDialogBox(me)
  212.   else
  213.     if nextAction = #new then
  214.       set nextAction to EMPTY
  215.       reset(appMgr)
  216.     else
  217.       if nextAction = #EXPORT then
  218.         set nextAction to EMPTY
  219.         doExportDialogBox(me)
  220.       else
  221.         if nextAction = #quit then
  222.           set nextAction to EMPTY
  223.           justQUit(appMgr)
  224.         else
  225.           updateFileNameField(appMgr)
  226.         end if
  227.       end if
  228.     end if
  229.   end if
  230. end
  231.  
  232. on getNewFileName me
  233.   set fileList to []
  234.   set toonDataFileList to []
  235.   set fileNameList to []
  236.   repeat with i = 1 to the maxinteger
  237.     set toonDataFile to getNthFileNameInFolder(toondataPath, i)
  238.     if toonDataFile = EMPTY then
  239.       exit repeat
  240.       next repeat
  241.     end if
  242.     append(fileList, toonDataFile)
  243.   end repeat
  244.   if fileList = EMPTY then
  245.     return 1000
  246.   else
  247.     sort(fileList)
  248.     repeat with theFileNumber in fileList
  249.       if fileNameIsNumber(me, theFileNumber) then
  250.         set tempFileDataList to readFileListData(me, theFileNumber)
  251.         if tempFileDataList <> EMPTY then
  252.           append(fileNameList, theFileNumber)
  253.         end if
  254.       end if
  255.     end repeat
  256.     sort(fileNameList)
  257.     return integer(getLast(fileNameList) + 1)
  258.   end if
  259. end
  260.  
  261. on readToonData me, index
  262.   if playBackMode <> #ReturnFromExport then
  263.     set the visible of openDialogBox to 0
  264.     updateStage()
  265.     cursor(4)
  266.     showStatusBar("Opening Cartoon...")
  267.   else
  268.     cursor(4)
  269.     showStatusBar("Resetting Cartoon Studio...")
  270.     set playBackMode to #NIL
  271.   end if
  272.   updateStatusBar(1)
  273.   reset(appMgr)
  274.   updateStatusBar(1)
  275.   set toonDataFileName to getToonDataFileName(me, index)
  276.   updateStatusBar(1)
  277.   readFILEIO(me)
  278.   updateStatusBar(1)
  279.   if PCflag then
  280.     preloadCartoon(listMgr)
  281.   end if
  282.   updateStatusBar(1)
  283.   setCurrentCartoonName(me, getAt(fileDataList, 1))
  284.   updateStatusBar(1)
  285.   setCurrentCartoonCredits(me, getAt(fileDataList, 2))
  286.   updateStatusBar(1)
  287.   set contentList to getAt(fileDataList, 4)
  288.   updateStatusBar(1)
  289.   updateFileNameField(appMgr)
  290.   updateStatusBar(1)
  291.   update(stackMgr)
  292.   updateStatusBar(1)
  293.   rewind(playbackMgr)
  294.   updateStatusBar(1)
  295.   updateTheBrain(appMgr)
  296.   updateStatusBar(100)
  297.   cursor(-1)
  298. end
  299.  
  300. on getToonDataFileName me, index
  301.   if PCflag then
  302.     return getAt(sortedFileList, index)
  303.   else
  304.     return getNthFileNameInFolder(toondataPath, index)
  305.   end if
  306. end
  307.  
  308. on deleteCartoon me, index
  309.   set the visible of openDialogBox to 0
  310.   updateStage()
  311.   set toonDataFileNameToDelete to getToonDataFileName(me, index)
  312.   if toonDataFileNameToDelete = toonDataFileName then
  313.     set theMessage to "The cartoon you are deleting is currently open.  Do you want to close and delete the current cartoon?"
  314.     set theAlertBoxType to #cancel_ok
  315.     showTheAlertBox(theMessage, theAlertBoxType, "nothing", "nothing", "resetAndDelete(fileMgr,toonDataFileNameToDelete)")
  316.   else
  317.     deleteToonData(me, toonDataFileNameToDelete)
  318.   end if
  319. end
  320.  
  321. on resetAndDelete me, toonDataFileNameToDelete
  322.   deleteToonData(me, toonDataFileNameToDelete)
  323.   reset(appMgr)
  324. end
  325.  
  326. on deleteToonData me, toonDataFileNameToDelete
  327.   cursor(4)
  328.   showStatusBar("Deleting Cartoon...")
  329.   updateStatusBar(1)
  330.   if objectp(fileObj) then
  331.     fileObj(mdispose)
  332.   end if
  333.   updateStatusBar(1)
  334.   set fileObj to FileIO(mnew, "write", toondataPath & toonDataFileNameToDelete)
  335.   updateStatusBar(1)
  336.   if objectp(fileObj) then
  337.     fileObj(mDelete)
  338.   end if
  339.   updateStatusBar(1)
  340.   if objectp(fileObj) then
  341.     fileObj(mdispose)
  342.   end if
  343.   updateStatusBar(100)
  344.   cursor(-1)
  345. end
  346.  
  347. on buildToonDataFileList me
  348.   set unsortedFileList to []
  349.   set sortedFileList to []
  350.   set toonDataFileList to []
  351.   repeat with i = 1 to the maxinteger
  352.     set toonDataFile to getNthFileNameInFolder(toondataPath, i)
  353.     if toonDataFile = EMPTY then
  354.       exit repeat
  355.       next repeat
  356.     end if
  357.     append(sortedFileList, toonDataFile)
  358.   end repeat
  359.   if sortedFileList <> EMPTY then
  360.     set unsortedFileList to copyList(sortedFileList)
  361.     sort(sortedFileList)
  362.     repeat with theFileNumber in sortedFileList
  363.       if fileNameIsNumber(me, theFileNumber) then
  364.         set tempFileDataList to readFileListData(me, theFileNumber)
  365.         if tempFileDataList <> EMPTY then
  366.           append(toonDataFileList, tempFileDataList)
  367.         end if
  368.       end if
  369.     end repeat
  370.   end if
  371. end
  372.  
  373. on fileNameIsNumber me, fileName
  374.   set isNumber to 1
  375.   repeat with i = 1 to 4
  376.     set checkNum to value(char i of fileName)
  377.     if not integerp(checkNum) then
  378.       set isNumber to 0
  379.       exit repeat
  380.     end if
  381.   end repeat
  382.   return isNumber
  383. end
  384.  
  385. on readFileListData me, newIndex
  386.   if objectp(fileObj) then
  387.     fileObj(mdispose)
  388.   end if
  389.   set fileObj to FileIO(mnew, "read", toondataPath & newIndex)
  390.   if objectp(fileObj) then
  391.     set toondataCheckStr to value(fileObj(mReadToken, breakChar, breakChar))
  392.     if listp(toondataCheckStr) then
  393.       if count(toondataCheckStr) = 3 then
  394.         set tempFileDataList to value(fileObj(mReadToken, breakChar, breakChar))
  395.       else
  396.         set tempFileDataList to EMPTY
  397.       end if
  398.     else
  399.       set tempFileDataList to EMPTY
  400.     end if
  401.   end if
  402.   if objectp(fileObj) then
  403.     fileObj(mdispose)
  404.   end if
  405.   return tempFileDataList
  406. end
  407.  
  408. on flattenCredits me, cartoonCredits
  409.   set tempString to EMPTY
  410.   put line 1 of cartoonCredits after tempString
  411.   repeat with i = 2 to the number of lines in cartoonCredits
  412.     put QUOTE & "& RETURN &" & QUOTE & line i of cartoonCredits after tempString
  413.   end repeat
  414.   return tempString
  415. end
  416.  
  417. on setCurrentCartoonName me, theCartoonName
  418.   set currentCartoonName to theCartoonName
  419.   setAt(fileDataList, 1, currentCartoonName)
  420. end
  421.  
  422. on getCurrentCartoonName me
  423.   return currentCartoonName
  424. end
  425.  
  426. on setCurrentCartoonCredits me, theCartoonCredits
  427.   set currentCartoonCredits to theCartoonCredits
  428.   setAt(fileDataList, 2, currentCartoonCredits)
  429. end
  430.  
  431. on getCurrentCartoonCredits me
  432.   return currentCartoonCredits
  433. end
  434.  
  435. on clearToonDataFileName me
  436.   set toonDataFileName to EMPTY
  437. end
  438.  
  439. on makeCartoonForPlayer me, fileIndex
  440.   set the visible of exportDialogBox to 0
  441.   updateStage()
  442.   set playBackMode to #export_part1
  443.   if PCflag then
  444.     set xFileList to copyList(unsortedFileList)
  445.     sort(xFileList)
  446.     set toonDataFile to getAt(xFileList, fileIndex)
  447.     set indexOfFileToExport to getPos(unsortedFileList, toonDataFile)
  448.   else
  449.     saveStateOfToolBox(me)
  450.     set indexOfFileToExport to fileIndex
  451.     set toonDataFile to getNthFileNameInFolder(toondataPath, indexOfFileToExport)
  452.   end if
  453.   set theMemorySize to getAt(readFileListData(me, toonDataFile), 3)
  454.   set theFreeDiskSpace to getFreeDiskSpace(me)
  455.   set theNeededDiskSpace to theMemorySize * 3
  456.   if theNeededDiskSpace > theFreeDiskSpace then
  457.     set theSpaceNeeded to integer(theNeededDiskSpace - theFreeDiskSpace)
  458.     set theMessage to "Sorry, not enough disk space to make a cartoon." & RETURN & "An additional " & theSpaceNeeded & "K needed."
  459.     set theAlertBoxType to #OK
  460.     showTheAlertBox(theMessage, theAlertBoxType, "nothing", "nothing", "nothing")
  461.     exit
  462.   end if
  463.   unLoad()
  464.   set theMemorySize to theMemorySize + 500
  465.   set theFreeKB to the freeBytes / 1024
  466.   if theMemorySize < theFreeKB then
  467.     go("EXPORT", the moviePath & "xtmpl")
  468.   else
  469.     set theRAMNeeded to integer(theMemorySize - theFreeKB)
  470.     set theMessage to "Sorry, not enough memory to make a cartoon." & RETURN & "An additional " & theRAMNeeded & "K needed."
  471.     set theAlertBoxType to #OK
  472.     showTheAlertBox(theMessage, theAlertBoxType, "nothing", "nothing", "nothing")
  473.   end if
  474. end
  475.  
  476. on getFreeDiskSpace me
  477.   if PCflag then
  478.     set drvLst to ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"]
  479.     set drv to char 1 of exportPath
  480.     set driveFound to 0
  481.     repeat with n = 1 to count(drvLst)
  482.       if drv = getAt(drvLst, n) then
  483.         set d to n
  484.         set driveFound to 1
  485.         exit repeat
  486.       end if
  487.     end repeat
  488.     if not driveFound then
  489.       set d to 0
  490.     end if
  491.     set freeSpace to MSfileObj(mgetdiskfree, d)
  492.     return value(freeSpace) / 1024
  493.   else
  494.     set the itemDelimiter to ":"
  495.     set v to item 1 of exportPath
  496.     GetVInfo(v)
  497.     set vInfo to the result
  498.     set the itemDelimiter to ","
  499.     return value(item 2 of vInfo)
  500.   end if
  501. end
  502.  
  503. on exportToonData me, fileIndex, theCartoonName
  504.   set the visible of exportDialogBox to 0
  505.   updateStage()
  506.   doExportToonData(me, fileIndex, theCartoonName)
  507. end
  508.  
  509. on importToonData me
  510.   set the visible of openDialogBox to 0
  511.   updateStage()
  512.   doImportToonData(me)
  513. end
  514.  
  515. on doExportToonData me, fileIndex, theCartoonName
  516.   set whichFile to getToonDataFileName(me, fileIndex)
  517.   set newFileName to theCartoonName
  518.   if PCflag then
  519.     set newFileName to makeDOSLegalName(me, newFileName) & ".ctd"
  520.   else
  521.     set newFileName to newFileName & ".ctd"
  522.   end if
  523.   set theFileExists to 0
  524.   repeat with count = 1 to the maxinteger
  525.     set theCheckFileName to getNthFileNameInFolder(exportPath, count)
  526.     if theCheckFileName = newFileName then
  527.       set theFileExists to 1
  528.       exit repeat
  529.       next repeat
  530.     end if
  531.     if theCheckFileName = EMPTY then
  532.       exit repeat
  533.     end if
  534.   end repeat
  535.   if theFileExists then
  536.     set theMessage to "The file" && newFileName && "already exists.  Replace it?"
  537.     set theAlertBoxType to #cancel_ok
  538.     set btn1script to "nothing"
  539.     set btn2script to "nothing"
  540.     set btn3script to "copyFile(fileMgr," & whichFile & "," & QUOTE & newFileName & QUOTE & ")"
  541.     showTheAlertBox(theMessage, theAlertBoxType, btn1script, btn2script, btn3script)
  542.   else
  543.     copyFile(me, whichFile, newFileName)
  544.   end if
  545.   if not PCflag then
  546.     setFileType(me, newFileName)
  547.   end if
  548. end
  549.  
  550. on setFileType me, fileName
  551.   if objectp(fileObj) then
  552.     fileObj(mdispose)
  553.   end if
  554.   set fileObj to FileIO(mnew, "read", exportPath & fileName)
  555.   if objectp(fileObj) then
  556.     fileObj(mSetFinderInfo, "M!93", "SCTB")
  557.     fileObj(mdispose)
  558.   end if
  559. end
  560.  
  561. on copyFile me, whichFile, newFileName
  562.   cursor(4)
  563.   showStatusBar("Exporting Toon to Export Folder")
  564.   updateStatusBar(1)
  565.   if PCflag then
  566.     MSfileObj(mCopyFile, toondataPath & whichFile, exportPath & newFileName)
  567.     updateStatusBar(1)
  568.   else
  569.     set err to FileCopy(toondataPath & whichFile, exportPath & newFileName, "TRUE", "DontShowProgress")
  570.     if err <> (exportPath & newFileName) then
  571.       showTheAlertBox(err, #OK, EMPTY, EMPTY, EMPTY)
  572.     end if
  573.     updateStatusBar(1)
  574.   end if
  575.   updateStatusBar(100)
  576.   cursor(-1)
  577. end
  578.  
  579. on doImportToonData me
  580.   set theMessage to the text of field "Demo Message"
  581.   set theAlertBoxType to #OK
  582.   showTheAlertBox(theMessage, theAlertBoxType, "nothing", "nothing", "nothing")
  583. end
  584.  
  585. on doImportToonData2 me
  586.   cursor(4)
  587.   showStatusBar("Importing ToonData")
  588.   updateStatusBar(1)
  589.   set theFileName to fileObj(mFileName)
  590.   updateStatusBar(1)
  591.   fileObj(mdispose)
  592.   updateStatusBar(1)
  593.   set theNewIndex to getNewFileName(me)
  594.   updateStatusBar(1)
  595.   if PCflag then
  596.     MSfileObj(mCopyFile, theFileName, toondataPath & theNewIndex)
  597.     updateStatusBar(1)
  598.   else
  599.     set err to FileCopy(theFileName, toondataPath & theNewIndex, "DontShowProgress")
  600.     if err <> (toondataPath & theNewIndex) then
  601.       showTheAlertBox(err, #OK, EMPTY, EMPTY, EMPTY)
  602.     end if
  603.     updateStatusBar(1)
  604.   end if
  605.   updateStatusBar(100)
  606.   cursor(-1)
  607. end
  608.  
  609. on deleteXTMPLworkfiles me
  610.   if objectp(fileObj) then
  611.     fileObj(mdispose)
  612.   end if
  613.   set fileObj to FileIO(mnew, "write", the moviePath & "xtmpl2.dir")
  614.   if objectp(fileObj) then
  615.     fileObj(mDelete)
  616.   end if
  617.   if objectp(fileObj) then
  618.     fileObj(mdispose)
  619.   end if
  620.   set fileObj to FileIO(mnew, "write", dlogdataPath & "xtmpl3.dir")
  621.   if objectp(fileObj) then
  622.     fileObj(mDelete)
  623.   end if
  624.   if objectp(fileObj) then
  625.     fileObj(mdispose)
  626.   end if
  627. end
  628.  
  629. on makeDOSLegalName me, newFileName
  630.   set oldDelimiter to the itemDelimiter
  631.   set the itemDelimiter to "."
  632.   repeat with itemNumber = 1 to the number of items in newFileName
  633.     set newFileName2 to newFileName2 & item itemNumber of newFileName
  634.   end repeat
  635.   set the itemDelimiter to oldDelimiter
  636.   set newFileName to EMPTY
  637.   repeat with count = 1 to the number of words in newFileName2
  638.     set newFileName to newFileName & word count of newFileName2
  639.   end repeat
  640.   set theFileName to truncateFileName(me, newFileName)
  641.   return theFileName
  642. end
  643.  
  644. on truncateFileName me, theName
  645.   if length(theName) >= 8 then
  646.     set theName to chars(theName, 1, the number of chars in theName - 1)
  647.     return truncateFileName(me, theName)
  648.   else
  649.     return theName
  650.   end if
  651. end
  652.  
  653. on updateContentList me
  654.   set found to 0
  655.   set bgdCastNumber to getAt(getAt(bgdData, 1), 1)
  656.   repeat with i = 1 to the number of lines in field "SCEdata"
  657.     set testItem to item 4 of line i of field "SCEdata"
  658.     set testItem to chars(testItem, 1, length(testItem) - 1)
  659.     if testItem = bgdCastNumber then
  660.       set bgdDataRecord to value(line i of field "SCEdata")
  661.       set found to 1
  662.       exit repeat
  663.     end if
  664.   end repeat
  665.   if not found then
  666.     repeat with i = 1 to the number of lines in field "SOLdata"
  667.       set testItem to item 4 of line i of field "SOLdata"
  668.       set testItem to chars(testItem, 1, length(testItem) - 1)
  669.       if testItem = bgdCastNumber then
  670.         set bgdDataRecord to value(line i of field "SOLdata")
  671.         set found to 1
  672.         exit repeat
  673.       end if
  674.     end repeat
  675.   end if
  676.   if found then
  677.     setAt(contentList, 1, getAt(bgdDataRecord, 3))
  678.   else
  679.     setAt(contentList, 1, EMPTY)
  680.   end if
  681.   set listOfCharacters to []
  682.   repeat with theLayer in dispatchTable
  683.     if getAt(theLayer, 1) = "C" then
  684.       append(listOfCharacters, getAt(theLayer, 2))
  685.     end if
  686.   end repeat
  687.   setAt(contentList, 2, listOfCharacters)
  688. end
  689.  
  690. on updateToonData me, index, newCredits, whichWindow
  691.   set prevToonDataFileName to toonDataFileName
  692.   if whichWindow = #open then
  693.     set theDialogBox to openDialogBox
  694.   else
  695.     set theDialogBox to exportDialogBox
  696.   end if
  697.   tell theDialogBox
  698.     cursor(4)
  699.   end tell
  700.   set toonDataFileName to getToonDataFileName(me, index)
  701.   readFILEIO(me)
  702.   setAt(fileDataList, 2, flattenCredits(me, newCredits))
  703.   writeFILEIO(me)
  704.   set toonDataFileName to prevToonDataFileName
  705.   readFILEIO(me)
  706.   tell theDialogBox
  707.     cursor(-1)
  708.   end tell
  709. end
  710.  
  711. on readFILEIO me
  712.   if objectp(fileObj) then
  713.     fileObj(mdispose)
  714.   end if
  715.   set fileObj to FileIO(mnew, "read", toondataPath & toonDataFileName)
  716.   if objectp(fileObj) then
  717.     set toondataCheckStr to value(fileObj(mReadToken, breakChar, breakChar))
  718.     updateStatusBar(1)
  719.     set fileDataList to value(fileObj(mReadToken, breakChar, breakChar))
  720.     updateStatusBar(1)
  721.     set bgdData to value(fileObj(mReadToken, breakChar, breakChar))
  722.     updateStatusBar(1)
  723.     set bgdFXData to value(fileObj(mReadToken, breakChar, breakChar))
  724.     updateStatusBar(1)
  725.     set fgdFXData to value(fileObj(mReadToken, breakChar, breakChar))
  726.     updateStatusBar(1)
  727.     set soundFXData to value(fileObj(mReadToken, breakChar, breakChar))
  728.     updateStatusBar(1)
  729.     set soundLoopData to value(fileObj(mReadToken, breakChar, breakChar))
  730.     updateStatusBar(1)
  731.     set dispatchTable to value(fileObj(mReadToken, breakChar, breakChar))
  732.     updateStatusBar(1)
  733.     set fileLength to fileObj(mGetLength)
  734.     set scoreData to []
  735.     set tempList to []
  736.     repeat with i = 1 to the maxinteger
  737.       set curFilePos to fileObj(mGetPosition)
  738.       if curFilePos >= (fileLength - 1) then
  739.         exit repeat
  740.       end if
  741.       set tempList to value(fileObj(mReadToken, breakChar, breakChar))
  742.       updateStatusBar(1)
  743.       repeat with theFrame in tempList
  744.         append(scoreData, theFrame)
  745.       end repeat
  746.       updateStatusBar(1)
  747.     end repeat
  748.   end if
  749.   if objectp(fileObj) then
  750.     fileObj(mdispose)
  751.   end if
  752. end
  753.  
  754. on writeFILEIO me
  755.   if objectp(fileObj) then
  756.     fileObj(mdispose)
  757.   end if
  758.   updateStatusBar(1)
  759.   set fileObj to FileIO(mnew, "write", toondataPath & toonDataFileName)
  760.   updateStatusBar(1)
  761.   if objectp(fileObj) then
  762.     set toondataCheckStr to line 1 of field "toondataCheckStrings"
  763.     fileObj(mWriteString, string(toondataCheckStr) & breakChar)
  764.     updateStatusBar(1)
  765.     fileObj(mWriteString, string(fileDataList) & breakChar)
  766.     updateStatusBar(1)
  767.     fileObj(mWriteString, string(bgdData) & breakChar)
  768.     updateStatusBar(1)
  769.     fileObj(mWriteString, string(bgdFXData) & breakChar)
  770.     updateStatusBar(1)
  771.     fileObj(mWriteString, string(fgdFXData) & breakChar)
  772.     updateStatusBar(1)
  773.     fileObj(mWriteString, string(soundFXData) & breakChar)
  774.     updateStatusBar(1)
  775.     fileObj(mWriteString, string(soundLoopData) & breakChar)
  776.     updateStatusBar(1)
  777.     fileObj(mWriteString, string(dispatchTable) & breakChar)
  778.     updateStatusBar(1)
  779.     set scoreDataLength to count(scoreData)
  780.     updateStatusBar(1)
  781.     set maxFrames to scoreDataLength / 120
  782.     updateStatusBar(1)
  783.     set leftOverFrames to scoreDataLength mod 120
  784.     updateStatusBar(1)
  785.     set frameCount to 1
  786.     updateStatusBar(1)
  787.     set tempList to []
  788.     updateStatusBar(1)
  789.     repeat with j = 1 to maxFrames
  790.       repeat with i = 1 to 120
  791.         append(tempList, getAt(scoreData, frameCount))
  792.         set frameCount to frameCount + 1
  793.       end repeat
  794.       fileObj(mWriteString, string(tempList) & breakChar)
  795.       set tempList to []
  796.       updateStatusBar(1)
  797.     end repeat
  798.     if leftOverFrames > 0 then
  799.       repeat with i = 1 to leftOverFrames
  800.         append(tempList, getAt(scoreData, frameCount))
  801.         set frameCount to frameCount + 1
  802.       end repeat
  803.       fileObj(mWriteString, string(tempList) & breakChar)
  804.     end if
  805.     updateStatusBar(1)
  806.   end if
  807.   fileObj(mSetFinderInfo, "M!93", "SCTB")
  808.   if objectp(fileObj) then
  809.     fileObj(mdispose)
  810.   end if
  811. end
  812.  
  813. on saveStateOfToolBox me
  814.   if toonDataFileName <> EMPTY then
  815.     set found to 0
  816.     repeat with i = 1 to the maxinteger
  817.       if toonDataFileName = getNthFileNameInFolder(toondataPath, i) then
  818.         set found to 1
  819.         exit repeat
  820.       end if
  821.     end repeat
  822.     if found then
  823.       set savedToonDataIndex to i
  824.     else
  825.       set savedToonDataIndex to 0
  826.     end if
  827.   else
  828.     set savedToonDataIndex to 0
  829.   end if
  830. end
  831.